<template>
	<view class="cancel-order">
		<view class="title-icon">
			<view></view>
			<view class="cancel-order-title">
				订单取消
			</view>
			<view class="cancel-order-icon" @click="returnPreview">
				<uni-icons type="closeempty"></uni-icons>
			</view>
		</view>
		<view class="notices">
			取消后无法恢复，优惠券、积分等可退回，有效期内使用
		</view>
		<view class="select-reason">
			<view class="select-reason-text">
				请选择取消订单原因
			</view>
			<view class="reason-list">
				<view class="reason-item" v-for="(item,index) in resonList" :key="index">
					<view class="reason-text" @click="selectReason(item)">
						{{item.reasonName}}
					</view>
					<view class="reason-check">
						<label class="radio">
							<radio :checked="item.isChecked" @click="selectReason(item)" />
						</label>
					</view>
				</view>
			</view>
			<!-- 如果点击其他就显示一个输入框，输入其他原因 -->
			<view class="other-reason-input" v-show="otherReasonInputShow">
				<uni-easyinput type="textarea" placeholder="请输入取消原因"></uni-easyinput>
			</view>
		</view>



		<!-- 底部按钮 -->
		<view class="btn-cancel-order">
			<button class="no-cancel-btn" @click="returnPreview">暂不取消</button>
			<button class="cancel-btn" @click="confirmCancel">确定取消</button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				resonList: [{
						reasonId: 1,
						reasonName: '暂时不需要了',
						isChecked: true,
					},
					{
						reasonId: 2,
						reasonName: '规格/款式/数量拍错',
						isChecked: false,
					},
					{
						reasonId: 3,
						reasonName: '收货地址填错',
						isChecked: false,
					},
					{
						reasonId: 4,
						reasonName: '价格有点贵',
						isChecked: false,
					},
					{
						reasonId: 5,
						reasonName: '其他',
						isChecked: false,
					}
				],
				otherReasonInputShow: false,
			};
		},
		methods: {
			returnPreview() {
				this.$emit('click-cloes');
			},
			selectReason(item) {
				if (!item.isChecked) {
					this.resonList.forEach(obj => {
						obj.isChecked = false;
					});
					item.isChecked = true;
				}
				if(item.reasonId === 5 && item.reasonName === '其他'){
					this.otherReasonInputShow = true;
				}else {
					this.otherReasonInputShow = false;
				}
			},
			confirmCancel(){
				console.log('确定取消');
			},
		},
	};
</script>

<style lang="scss" scoped>
	.cancel-order {
		width: 100%;
		height: 70vh;
		overflow-y: scroll;
		background-color: #fff;
		border-radius: 10px 10px 0 0;
		padding-bottom: 200rpx;

		.title-icon {
			height: 100rpx;
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			margin-left: auto;
			margin-right: auto;
			padding-top: 50rpx;
			display: flex;
			justify-content: space-around;
			background-color: #f8f8f8;
			z-index: 1;

			.cancel-order-title {
				font-size: 40rpx;
				letter-spacing: 3rpx;
			}

			.cancel-order-icon {
				width: 50rpx;
				height: 50rpx;
				border-radius: 10rpx;
				box-shadow: 0 0 10px 5px rgba(209, 209, 209, 0.6);
				display: flex;
				align-items: center;
				justify-content: center;
				text-align: center;
				background-color: #f8f8f8;
				
			}
		}

		.notices {
			margin-top: 200rpx;
			width: 90%;
			margin-left: auto;
			margin-right: auto;
			padding: 15rpx;
			border-radius: 10rpx;
			background-color: #f8f8f8;
			font-size: 20rpx;
			letter-spacing: 3rpx;
			text-align: center;
			color: #7c7c7c;
		}

		.select-reason {
			margin-top: 50rpx;
			width: 90%;
			margin-left: auto;
			margin-right: auto;

			.select-reason-text {
				color: #b4b4b4;
				letter-spacing: 3rpx;
			}

			.reason-list {

				.reason-item {
					margin-top: 40rpx;
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;

					.reason-text {
						font-size: 27rpx;
						letter-spacing: 2rpx;
					}

					.reason-check {}
				}
			}
			
			.other-reason-input{
				margin-top: 30rpx;
			}
		}

		.btn-cancel-order {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			background-color: #f8f8f8;
			height: 150rpx;
			display: flex;
			justify-content: space-evenly;
			align-items: center;

			.no-cancel-btn {
				height: 80rpx;
				width: 45%;
				background-color: #eeeeee;
				border-radius: 30rpx;
				box-shadow: 0 0 0 1rpx #000; // 这行代码用于模拟边框，四个参数分别表示水平偏移量、垂直偏移量、模糊半径、扩展半径（这里扩展半径设为2px来模拟边框宽度）以及颜色，可以根据需要调整颜色和宽度
				color: #000;
				letter-spacing: 3rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.cancel-btn {
				height: 80rpx;
				width: 45%;
				background-color: #66596b;
				box-shadow: 0 0 0 2px #66596b;
				border-radius: 30rpx;
				color: #fff;
				letter-spacing: 3rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>